<?php

class rooms_model extends MY_Model {

    function __construct() {
        parent::__construct();
        $this->table = 'rooms';
    }

    function find_all_rooms($object_ID) {
        $q = "
            SELECT rooms.*,
            room_type.name
            FROM rooms
            LEFT JOIN room_type ON
            rooms.room_type_ID = room_type.ID
            WHERE objects_ID =  $object_ID
            ";

        $res = $this->db->query($q)->result_array();
        return $res;
    }

    function find_all_rooms_fixcolumn_names() {
        $q = "
            SELECT 
            rooms.ID as room_ID, rooms.room_type_ID, rooms.service_type_ID, 
            rooms.description, rooms.max_person, rooms.available_units,
            rooms.objects_ID as object_ID, rooms.selling_billing_type_ID,
            rooms.net_billing_type_ID, rooms.information, rooms.cancellation,
            room_type.name
            FROM rooms
            LEFT JOIN room_type ON
            rooms.room_type_ID = room_type.ID
            ";

        $res = $this->db->query($q)->result_array();
        return $res;
    }

    function find_by_id_fixcolumn_names($room_ID) {
        $q = "
            SELECT 
            rooms.ID as room_ID, rooms.room_type_ID, rooms.service_type_ID, 
            rooms.description, rooms.max_person, rooms.available_units,
            rooms.objects_ID as object_ID, rooms.selling_billing_type_ID,
            rooms.net_billing_type_ID, rooms.information, rooms.cancellation,
            room_type.name,
            service_type.name as service_name
            FROM rooms
            LEFT JOIN room_type ON
            rooms.room_type_ID = room_type.ID
            LEFT JOIN service_type ON
            rooms.service_type_ID = service_type.ID
            WHERE rooms.ID =  $room_ID
            ";

        $res = $this->db->query($q)->row_array();
        return $res;
    }
    
    function find_by_id($room_ID) {
        $q = "
            SELECT rooms.*,
            room_type.name,
            service_type.name as service_name
            FROM rooms
            LEFT JOIN room_type ON
            rooms.room_type_ID = room_type.ID
            LEFT JOIN service_type ON
            rooms.service_type_ID = service_type.ID
            WHERE rooms.ID =  $room_ID
            ";

        $res = $this->db->query($q)->row_array();
        return $res;
    }

    function delete_all($object_ID) {
        $q = "
            DELETE FROM rooms
            WHERE objects_ID =  $object_ID
            ";

        $res = $this->db->query($q);
        return $res;
    }

}

?>
